var imgarray; 
var currentimg=0;
var imgarraylength;
var dotblackpath="img/custom_dotblack.gif";
var dotwhitepath="img/custom_dotwhite.gif";
var moneyowner;
var sharesId;
var sharesusersName; 
var filecount=0;
function getTop(height){
	var windowheight=window.innerHeight;
	return (windowheight-height)/2;
}
function getLeft(width){
	var windowwidth=window.innerWidth;
	return (windowwidth-width)/2;
}
function FriendRank1Link(){
	$(".friendrank1").click(function(){
		//window.open();//此处打开用户中心页面
		window.open("getFriendOwnMessageAction?uname="+$(this).get(0).id);
	});
}
function FriendRank2Link(){
	$(".friendrank2").click(function(){
		//window.open();//此处还需要打开用户中心页面
		window.open("getFriendOwnMessageAction?uname="+$(this).html().trim());
	});
}
function ProRank1Link(){
	$(".pro_rank1").click(function(){
		//windw.open();//此处根据产品的customId识别产品
		window.open("ShareInfo?_id="+$(this).get(0).id);
	});
}
function ProRank2Link(){
	$(".pro_rank2").click(function(){
		//window.open();//此处根据用户名username打开用户中心
		window.open("ShareInfo?_id="+$(this).get(0).id);		
	});
}
function ProCommentLink(){
	$(".userface").click(function(){
		//window.open();//此处根据用户名打开用户中心
		window.open("getFriendOwnMessageAction?uname="+$(this).get(0).id);
		
	});
}
$(document).ready(function () {
    var production = document.getElementById("production_img");
    $("#comment_content").val("");
    $("#moreshare_img").mouseover(function () {
        $("#moreshare_list").slideDown("slow");
    });
    $("#moreshare_list").mouseleave(function () {
        $(this).fadeOut("slow");
    });
    $("#turnleft_btn").click(function () {
        $("#production_img").fadeOut("slow", function () {
            changeimg("turnleft_btn");
            production.src = imgarray[currentimg];
            $("#production_img").slideDown("slow");
        });
    });
    $("#turnright_btn").click(function () {
        $("#production_img").fadeOut("slow", function () {
            changeimg("turnright_btn");
            production.src = imgarray[currentimg];
            $("#production_img").fadeIn("slow");
        });
    });
    $(".comment_publish").click(function(){
    	var comment_text=$("#comment_content").val();
    	if(comment_text.trim()!="")
    	{
    		var produc_id=document.getElementById("outside").getElementsByTagName("img").item(0).alt;
    		$.post("user_comment",{"production_id":produc_id,"comment_content":comment_text},function(){
    			alert("评论成功！");
    			$("#comment_content").val("");
    			window.location="ShareInfo?_id="+produc_id;
    		});
    	}
    	else{
    		alert("亲，内容不能为空哦！");
    	}
    });
    jPagesresign("itemContainer",".holder");
    dealproductionimg();
    sharefriendrank();
    sharerenqirank();
    jubaoresign();
    siliaoresign(); 
    ProCommentLink();
});
function jubaoresign(){
	$(".jubao").click(function(){
		var jubaolevel="<p id='jubao_username' style='text-align:left;'></p>"+
    	"<div style='height:auto; width:auto; float:left;"+
    	"font-family:Arial, Helvetica, sans-serif; font-weight:900; color:red;'>举报理由:</div>"+
    	"<textarea id='jubao_content' style='width:500px; height:80px;'></textarea>";
    	var jubaouser=$(this).parent().parent().parent().get(0).getElementsByTagName("a").item(1).innerHTML;
    	var commentId=$(this).get(0).id;
    	$("#jubao").append(jubaolevel).dialog({
    		width:640,
    		height:300,
    		modal:true,
    		position:[getLeft(640),getTop(300)],
    		buttons:{
    			确定:function(){
    				var jubao_content=$("#jubao_content").val();
    				if(jubao_content.length==0)
						alert("亲，您还没有输入举报的理由呢！");
					else{
						$.post('jubaoaction',{'jubao_content':jubao_content,
						'receive_user':jubaouser,'commentId':commentId},function(data){
							alert("举报成功，我们会对该举报进行审核！");
							$("#jubao_content").val("");
							$("#jubao").dialog("close");
						});
					}
    			},
    			取消:function(){
    				$("#jubao").html("");
    				$(this).dialog("close");
    			}
    		},
    		open:function(){
    			$("#jubao_username").html("被举报人:"+jubaouser);
    		}
    	});
    	$("#jubao").bind('dialogbeforeclose',function(){
            $("#jubao").html("");
        });
	});
}
function siliaoresign(){
	$(".siliao").click(function(){
		var uploadfilestr="<div style='margin-left:75px; text-align:left;' id='canremove'>"+
        		 "<div id='fileQueue' ></div>"+
        		 "<input type='file' name='uploadify' id='uploadify' />"+
         		 "<label id='shangchuan'>上传</label>&nbsp;&nbsp;<label id='cancle'>取消</label>"+
        		 "<div id='result'></div>"+"</div>";
        var receiveuser=$(this).parent().parent().parent().get(0).getElementsByTagName("a").item(1).innerHTML;
        var private_comment;
        var filepath='';
        $("#private_comm").append(uploadfilestr);
        $("#fileQueue").css("height","auto");
        $("#private_comm").dialog({
				width:670,
				height:450,
				modal:true,
				resizable:false,
				position:[getLeft(670),getTop(450)],
				open:function(){
					dialogstartheight=$("#private_comm").dialog('option','height');
					document.getElementById("content").focus();
					$("#receive_userame").val(receiveuser);
					$("#content").val("");
					$("#filename").val("");
					$("#shangchuan").click(function(){
						$('#uploadify').uploadifyUpload();
					});
					$("#cancle").click(function(){
						$('#uploadify').uploadifyClearQueue();
					});
   			   		$("#uploadify").uploadify({
                		'uploader'       : 'uploadify/uploadify.swf', //是组件自带的flash，用于打开选取本地文件的按钮 
                		'script'         : 'uploadAction',//处理上传的路径，这里使用Struts2是XXX.action 
                		'cancelImg'      : 'uploadify/cancel.png',//取消上传文件的按钮图片，就是个叉叉
                		'folder'         : receiveuser,//上传文件的目录
                		'fileDataName'   : 'uploadify',//和input的name属性值保持一致就好，Struts2就能处理了
                		'queueID'        : 'fileQueue',
                		'auto'           : false,//是否选取文件后自动上传
                		'multi'          : true,//是否支持多文件上传
                		'simUploadLimit' : 2,//每次最大上传文件数
                		'buttonText'     : 'BROWSE FILE',//按钮上的文字
                		'displayData'    : 'speed',//有speed和percentage两种，一个显示速度，一个显示完成百分比 
                		'fileDesc'       : '支持格式:jpg/gif/jpeg/png/bmp.', //如果配置了以下的'fileExt'属性，那么这个属性是必须的 
                		'fileExt'        : '*.jpg;*.gif;*.jpeg;*.png;*.bmp',//允许的格式
                		'onComplete'     : function (event, queueID, fileObj, response, data){
                   				filepath+=response+";";
                		},
                		'onSelect':function(){
                			filecount=filecount+1;
                			var height=$("#private_comm").dialog('option','height');
                			$("#private_comm").dialog('option','height',height+70);
                		},
                		'onCancle':function(event,queueId,fileObj,data){
                			filecount=data.fileCount;
                		},
                		'onClearQueue':function(){
                			filecount=0;
                			$("#private_comm").dialog('option','height',dialogstartheight);
                		}
            		});
				}, 
				buttons:{
					发送:function(){
						private_comment=document.getElementById("content").value;//内容
						if(private_comment.length==0)
						{
							alert("内容不能为空哦亲！");
						}
						else{
							var ques;
							if(filepath=='')
							{
								ques=window.confirm("亲，您暂时没有选择文件呦！");
							}
							$.post('siliaoaction',{'private_comment':private_comment,'receiveuser':receiveuser,'filepath':filepath},function(data){
								if(data=="success")
								{
									filepath="";
									$("#error").html("发送成功！").dialog({
										autoOpen:true,
										width:300,
										height:180,
										position:[getLeft(300),getTop(180)],
										buttons:{
											确定:function(){
												$(this).dialog("close");
												$("#private_comm").dialog("close");
												}
											}
										}
									);
								$("#content").val("");
								}
								else{
									alert("私聊不成功!");
								}
							});
						}
					},
					取消:function(){
						$("#canremove").remove();
						if(filepath!="")
						{
							$.post('deletefile',{"filepath":filepath},function(data){});
							filepath="";
						}
						$(this).dialog("close");
					}
				}
			});
			$("#private_comm").bind('dialogbeforeclose',function(){
				if(filepath!="")
				{
					$.post('deletefile',{"filepath":filepath},function(data){});
					filepath="";
				}
            	$("#canremove").remove();
            });
	});
}
function dealproductionimg(){
	var test=$("#productionimg").html();
	imgarray=test.split(";");
	imgarraylength=imgarray.length;
	$("#use_fancybox_showimg").get(0).getElementsByTagName("img").item(0).src = imgarray[0];
}
function jPagesresign(id,classname){
		$(""+classname).jPages({
			containerID: id,
            first: 'Home',
            last: 'Tear',
            previous: 'Previous',
            next: 'Next',
            perPage: 5,
            startPage: 1,
            startRange: 2,
            midRange: 3,
            endRange: 2,
            animation: '',
            keyBrowse: true,
            callback: function (pages, items) {
                 items.showing.find("img").trigger("turnPage");
                 items.oncoming.find("img").trigger("turnPage");
            }
		});
}
function sharerenqirank(){
	$.post("loadrenqirank",{},function(data){
		var pimg=eval("("+data.production_img+")");
		var pname=eval("("+data.production_name+")");
		var phot=eval("("+data.production_hot+")");
		var pid=eval("("+data.pro_id+")");
		var str="";
		for(var i=0;i<parseInt(data.total);i++)
		{
			str+="<div class='shareinfo_content_right_child' >" +
                "<div class='shareinfo_right_child_img' >" +
                    "<span class='pro_rank1' id='"+pid.P_id[i]+"'><img src='"+pimg.Pface[i]+"' ></span>" +
                "</div>" +
                "<div class='shareinfo_right_child_userinfo'>" +
                    "<div class='shareinfo_right_child_userinfo_name' >" +
                        "<span class='pro_rank2' id="+pid.P_id[i]+">"+pname.Pname[i]+"</span>" +
                    "</div>" +
                    "<div class='shareinfo_right_child_userinfo_message' >" +
                    "热度:<span>"+(phot.Phot[i])+"</span>" +
                    "</div>" +
                "</div>" +
          "</div>";
		}
		$("#itemContainer1").append(str);
		jPagesresign("itemContainer1",".holder1");
		$("a").attr("target","_blank");
		ProRank1Link();	
		ProRank2Link();
	});
}
function sharefriendrank(){
	$.post("loadfriendrank",{},function(data){
		var userface=eval("("+data.userface+")");
		var username=eval("("+data.username+")");
		var userhot=eval("("+data.userhot+")");
		var str="";
		for(var i=0;i<parseInt(data.total);i++)
		{
			str+="<div class='shareinfo_content_right_child' >" +
                "<div class='shareinfo_right_child_img' >" +
                    "<span class='friendrank1' id='"+username.username[i]+"'><img src='"+userface.userface[i]+"' ></span>" +
                "</div>" +
                "<div class='shareinfo_right_child_userinfo'>" +
                    "<div class='shareinfo_right_child_userinfo_name' >" +
                        "<span class='friendrank2'>"+username.username[i]+"</span>" +
                    "</div>" +
                    "<div class='shareinfo_right_child_userinfo_message' >" +
                    "人气:<span>"+(userhot.userhot[i])+"</span>" +
                    "</div>" +
                "</div>" +
          "</div>";
		}
		$("#itemContainer2").append(str);
		jPagesresign("itemContainer2",".holder2");
		$("a").attr("target","_blank");
		FriendRank1Link();
		FriendRank2Link();
	});
}
function changeimg(id)
{
	if(id=="turnleft_btn")
	{
		if(currentimg==0)
		{
			currentimg=imgarraylength-1;
		}
		else
		{
			currentimg=currentimg-1;
		}		
	}
	else if(id=="turnright_btn")
	{
		if(currentimg==imgarraylength-1)
		{
			currentimg=0;
		}
		else
		{
			currentimg=currentimg+1;
		}
	}
}
//function loadimg()//椤甸潰杞藉叆鐨勬椂鍊欏姩鎬佸姞杞藉浘鐗� 椤甸潰鍔犺浇鐨勬椂鍊欒灏嗘暟鎹姞杞借繘鏉ュ晩
//{
//    $.get("../ashxfile/shareinfo/load_sharesPics.ashx", {}, function (data) {//姝ゅ紓姝ュ姞杞芥槸鏍规嵁鍒嗕韩鐨剆haresId瀵瑰叾鍒嗕韩鍥剧墖杩涜鍔犺浇
//
//        var temp = new Array();
//        temp = data.split(';');
//        //alert(temp.length);
//        //imgarray = data.split(';'); //杩欎簺鏁版嵁鏄粠鍒嗕韩鍥剧墖瀛楁涓彇鍑虹殑
//        imgarray = new Array(temp.length - 4);
//        //alert(temp[temp.length-1]);
//        //alert(imgarray.length);
//        for (var i = 0; i < imgarray.length; i++) {
//            imgarray[i] = temp[i];
//        }
//
//        imgarraylength = imgarray.length;
//        $("#use_fancybox_showimg").get(0).getElementsByTagName("img").item(0).src = imgarray[0]; //杩欐牱鏃㈠彲浠ュ姞杞芥暟鎹簡
//        //$("#production_img").get(0).src = imgarray[0];
//        setimg = document.getElementById("fancybox_showimg");
//        $("#fancybox_showimg").fancybox(); //璨屼技鍏朵腑娌℃湁鍐呭鐨勮瘽 鏄笉鑳芥敞鍐岀殑
//        if (temp[temp.length - 3] == temp[temp.length - 4]) {
//            $("#editLevel").css({ "display": 'block' });
//        }
//        else {
//            $("#editLevel").css({ "display": 'none' });
//        }
//        moneyowner = temp[temp.length - 2]; //鑾峰緱鐨勬槸浣ｉ噾鑾峰緱鑰�
//        sharesId = parseInt(temp[temp.length - 1]); //鑾峰緱鍒嗕韩鐨刬d
//        sharesusersName = temp[temp.length - 4]; //鑾峰緱鍒嗕韩鑰呭悕绉�
//
//        $("#mydingzhi").get(0).href = "custom.aspx?owner=" + moneyowner + "&sharesId=" + sharesId;
//        $("#editlink").attr("href", "Toshare_pageEdit.aspx?sharesId=" + sharesId);
//    });
//}